package com.sagframe.sagacity.sqltoy.plus;


import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public interface SinFiledMappingStrategy extends FiledMappingStrategy {

    default String getSplitColumnName(Class<?> clazz, List<String> filedNames, String regex) {
        if (filedNames != null && !filedNames.isEmpty()) {
            return filedNames.stream().filter(Objects::nonNull).map(e -> getColumnName(clazz, e)).collect(Collectors.joining(regex));
        }
        return null;
    }


    /**
     * 默认字段映射策略
     */
    class DefaultFiledMappingStrategy implements SinFiledMappingStrategy {

        private DefaultFiledMappingStrategy() {}

        public static DefaultFiledMappingStrategy getInstance() {
            return DefaultFiledMappingStrategy.DefaultFiledMappingStrategyHolder.instance;
        }

        @Override
        public String getColumnName(Class<?> clazz, String filedName) {
            return filedName;
        }

        protected static class DefaultFiledMappingStrategyHolder {
            private static DefaultFiledMappingStrategy instance = new DefaultFiledMappingStrategy();
        }
    }
}
